package com.example.lib_common.video

import com.danikula.videocache.HttpProxyCacheServer
import com.example.lib_common.base.BaseApplication
import java.io.File

/**
 * 视频缓存
 */
object VideoCacheProxy {
    private var instance: HttpProxyCacheServer? = null
    private fun newProxy(): HttpProxyCacheServer?{
        try {
            return HttpProxyCacheServer.Builder(BaseApplication.instance)
                .cacheDirectory(File(BaseApplication.instance.externalCacheDir,"video-cache"))
                .build()
        }catch (e:Exception){
            e.printStackTrace()
        }
        return null
    }
    fun get(): HttpProxyCacheServer?{
        if (instance == null){
            synchronized(this){
                if (instance == null){
                    instance = newProxy()
                }
            }
        }
        return instance
    }
}